package com.tanhua.server.config;

import com.tanhua.server.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置类 类似于springmvc.xml中拦截器配置
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private TokenInterceptor tokenInterceptor;

    /**
     *
     * 将自定义拦截器添加spring容器中
     * @param registry
     */
    public void addInterceptors(InterceptorRegistry registry) {
        //哪些请求要拦截 哪些请求放行(登录-登录第一步---获取验证码 登录第二步---注册登录)
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login","/user/loginVerification");
    }
}
